home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3187 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.6 KB

  1. Path: dartvax.dartmouth.edu!usenet
  2. From: Mark.A.McPeek@dartmouth.edu (Mark A. McPeek)
  3. Newsgroups: comp.lang.c++
  4. Subject: Disk Write Problem
  5. Date: 22 Jan 1996 18:29:39 GMT
  6. Organization: Dartmouth College, Hanover, NH
  7. Message-ID: <4e0l2j$8jr@dartvax.dartmouth.edu>
  8. NNTP-Posting-Host: atgw-ksp-1-83.dartmouth.edu
  9. X-Posted-From: InterNews 1.0.6@dartmouth.edu
  10.  
  11. Hi.  I've recently switched programming platforms from Turbo C++ and
  12. OWL running on a 486 with Windows 3.1 to Borland C++ 4.52 and OWL
  13. running on a Pentium with Windows 95.  I'm trying to convert a program
  14. across this platform change.  
  15.  
  16. The code below is a segment that is giving me real problems. The code
  17. attempts to read in a text file of numbers from the harddisk.  If I
  18. comment out all the calls to the harddisk (as I have done below) the
  19. program runs fine.  The file opens and then closes and no errors are
  20. produced (that I know of).  If I remove the comments so that the calls
  21. are made to the disk, the program runs fine and the program reads all
  22. the data from the file correctly.  However, when I shut down the
  23. application from the application's menu, I receive a General Protection
  24. Exception message (Exception 13 to be exact).  This code segment ran
  25. fine (i.e., no GPE generated) on the Windows 3.1 platform.
  26.  
  27. Can anyone tell me what's going wrong here?  I would appreciate any
  28. advice or suggestions.  I do not regularly monitor this news group, so
  29. please respond to my e-mail address.
  30.  
  31. Thanks for any help!
  32.  
  33. Mark McPeek
  34. mark.mcpeek@dartmouth.edu
  35.  
  36.  
  37. //**********************************************************************
  38. *****
  39.  
  40. void contrastApp::GetData()
  41.     {
  42.     int NumIncomingSpp=0;         // Number of species to read from data
  43. file
  44.  
  45.     strcpy(TreeString,"");
  46.  
  47.     TOpenSaveDialog::TData fileData(OFN_FILEMUSTEXIST| OFN_HIDEREADONLY |
  48.             OFN_PATHMUSTEXIST,"All Files (*.*)|*.*",0, 0, "*");
  49.  
  50.     strcpy(fileData.FileName,"*.*");
  51.  
  52.     if (TFileOpenDialog(GetMainWindow(), fileData).Execute() != IDOK)
  53.         {
  54.         strcpy(msg, "No File was opened.");
  55.         MessageBox(0, msg,"Warning in GetData!", MB_OK | MB_ICONSTOP);
  56.         return;
  57.         };
  58.     ifstream infile(fileData.FileName, ios::in); // Open file for input
  59.     const int bufflength=1000;           // Length of Input Buffer
  60.     char inbuf[bufflength];              // Holds Buffer from file
  61.  
  62. /*
  63.  
  64.     infile.getline(inbuf,bufflength);
  65.     istrstream incoming(inbuf);
  66.  
  67.     incoming >> NumIncomingSpp >> NumChars >> AllBranchesFlag;
  68.     if (AllBranchesFlag==0)
  69.         {
  70.         NumSpp=NumIncomingSpp;
  71.         NumNodes=(2*NumSpp)-1;
  72.         }
  73.         else
  74.         {
  75.         NumSpp=(NumIncomingSpp-1)/2;
  76.         NumNodes=NumIncomingSpp;
  77.         }
  78.  
  79.     if (NumSpp>MaxSpp)
  80.         {
  81.         wsprintf(msg, "Number of Species in Data File too large (i.e., >
  82. %d)\nProgram Terminating.", MaxSpp);
  83.         MessageBox(0, msg,"Warning!", MB_OK | MB_ICONSTOP);
  84.         NumSpp=0; NumChars=0;
  85.         infile.close();    // Close Raw data file
  86.         exit(0);             // Terminate program
  87.         }
  88.     if (NumChars>MaxChars)
  89.         {
  90.         wsprintf(msg, "Number of Characters in Data File too large (i.e., >
  91. %d)\nProgram Terminating.", MaxChars);
  92.         MessageBox(0, msg,"Warning!", MB_OK | MB_ICONSTOP);
  93.         NumSpp=0; NumChars=0;
  94.         infile.close();    // Close Raw data file
  95.         exit(0);             // Terminate program
  96.         }
  97.     HoldData = new RawData[NumIncomingSpp];
  98.     infile.getline(TreeString, bufflength);
  99.  
  100.     for (i=0;i<NumIncomingSpp;i++)
  101.         {
  102.         infile.getline(inbuf,33);
  103.         strcpy(HoldData[i].Name,inbuf);     // Assign species label to Nodes
  104.         infile.getline(inbuf,bufflength);   // Take in data for this species
  105.         istrstream incoming(inbuf);
  106.         for (int j=0; j<NumChars; j++)
  107.             {
  108.             incoming >> HoldData[i].CharacterData[j];
  109.             }
  110.         }
  111. */
  112.  
  113.     infile.close();    // Close Raw data file
  114.  
  115.     }    // End contrastApp::GetData
  116.